/*
 * tourManageFrame.java
 *
 * Created on Mar 17, 2012, 1:26:26 PM
 */
package tourmsystem.tourmanaging.view;

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import tourmsystem.tourmanaging.classes.Definition;
import tourmsystem.tourmanaging.classes.Tour;
import tourmsystem.tourmanaging.classes.Tour_Customer;
import tourmsystem.tourmanaging.dao.TourController;

public class TourManageFrame extends javax.swing.JFrame {

    private Tour tour;
    private TourController controller;
    private ActionListener delAction;
    public static final String CB_XOA = "CB_XOA";
    /* phuong thuc khoi tao */
    public static final String CB_SUA = "CB_SUA";
    public static final String CB_MO = "CB_MO";

    public TourManageFrame(Tour tour) {
        super("Design and Manage Tours");
        this.controller = new TourController(tour, this);
        initComponents();
        initButtons();
    }

    public TourManageFrame(Tour tour, TourController controller) {
        super("Design and Manage Tours");
        this.controller = controller;
        this.tour = tour;
        initComponents();
        initButtons();

    }
    /* mo giao dien xoa tour */

    public void openForm() {
        tour_open_form.setSize(600, 400);
        tour_open_form.setVisible(true);
    }

    public void initButtons() {
//        bt_new_save.addActionListener(controller);
        btDelAction = new JButton("Xóa");
        btOpenTourFrame.addActionListener(controller);
        btOpenTour.addActionListener(controller);

        jPanelForTourView.add(jPanelTourInfo);
        btEdit.addActionListener(controller);
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        for (String i : Definition.TYPES) {
            model.addElement(i);
        }
        tf_new_type.setModel(model);
    }
    /*hien thi message thong bao */

    public void showWarning(String message) {
        JOptionPane.showMessageDialog(this, message);

    }

    public void refineDialog(String message) {

        final JOptionPane optionPane = new JOptionPane(
                "Do you really want to delete this ? ",
                JOptionPane.QUESTION_MESSAGE,
                JOptionPane.YES_NO_OPTION);
        final JDialog dialog = new JDialog(this,
                "Click a button",
                true);
        dialog.setContentPane(optionPane);
        dialog.setDefaultCloseOperation(
                JDialog.DO_NOTHING_ON_CLOSE);
        optionPane.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent e) {
                String prop = e.getPropertyName();
                if (dialog.isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                    dialog.setVisible(false);
                }
            }
        });
        dialog.pack();
        dialog.setVisible(true);

        int value = ((Integer) optionPane.getValue()).intValue();
        if (value == JOptionPane.YES_OPTION) {
            String sid = jComboBoxDelIds.getSelectedItem().toString();
            System.out.println("id xoa  = " + sid);
            try {
                if (controller.deleteTour("tour", "id", sid)) {
                    showWarning("xoa thanh cong!");
                    jComboBoxDelIds.removeItem(sid);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                Logger.getLogger(TourManageFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (value == JOptionPane.NO_OPTION) {
        }
    }

    public Tour convertFromStringToTour(String[] ts) throws Exception {
        Tour tour = new Tour();
        tour.setId(ts[0]);
        tour.setName(ts[1]);
        tour.setSchedule(ts[5]);
        System.out.println("ts 4" + ts[4]);
        tour.setType(Integer.parseInt(ts[4]));
        tour.setPrice(ts[6].length() == 0 ? 0f : Float.parseFloat(ts[6]));
        tour.setDiscount(ts[7].length() == 0 ? 0f : Float.parseFloat(ts[7]));
        tour.setDuration(ts[3].length() == 0 ? 0 : Integer.parseInt(ts[3]));
        tour.setMaxP(ts[8].length() == 0 ? 0 : Integer.parseInt(ts[8]));
        tour.setImgLink(ts[9]);
        DateFormat dsf = new SimpleDateFormat("dd/MM/yyyy");
//                String df = tf_new_stateDate.getText();
        Date d = dsf.parse(ts[2]);
        tour.setStartDate(d);
        return tour;
    }

    /*phuong thuc lay thong tin dang ky tu bang 
     * tra ve doi tuong Tour da duoc dong goi
     */
    public Tour getTourInput() {
        Tour tour = null;
        if (tf_new_id.getText().length() == 0) {
            showWarning("Bạn chưa nhập mã tour!");
        } else {

            try {
                String[] tourString = {tf_new_id.getText(), tf_new_name.getText(), tf_new_stateDate.getText(), tf_new_duration.getText(), tf_new_type.getSelectedIndex() + "", tf_new_schedule.getText(), tf_new_price.getText(), tf_new_discount.getText(), tf_new_maxnum1.getText(), tf_new_imgLink.getText()};
                System.out.println("tourString" + tourString);
                tour = convertFromStringToTour(tourString);
            } catch (Exception e) {
                showWarning("Thông tin nhập không đúng, lỗi +\n" + e.getMessage());
                e.printStackTrace();
            }
        }
        return tour;
    }
    /* hien thi bang thong tin tour*/

    public void addTable(ArrayList<Tour_Customer> openTours) {
        tour_open_form.setSize(600, 400);
        tour_open_form.setVisible(true);
        String[] columns = {"Ma", "Ten", "Ngay KH", "Trang thai", "So nguoi"};
        showDataToTable(openTours, jPanelTourOpenTable, columns);
//        if (tours != null) {
//            jComboBoxTourOpenId.setEnabled(true);
//            ArrayList<String> tourIds = new ArrayList<String>();
//            for (int i = 0; i < tours.size(); i++) {
//                tourIds.add(tours.get(i).getId());
//            }
//            DefaultComboBoxModel model = new DefaultComboBoxModel();
//            for (String i : tourIds) {
//                model.addElement(i);
//            }
//            jComboBoxTourOpenId.setModel(model);
//        } else {
//            jComboBoxTourOpenId.setEnabled(false);
//        }

    }
    /*show thong tin len bang mo tour*/

    public JTable showDataToTable(ArrayList<Tour_Customer> openTours, JPanel jP, String[] columns) {

        Vector<String> columNames = new Vector<String>();
        for (String s : columns) {
            columNames.addElement(s);
        }
        JTable table;
        Vector<Vector> rowData = new Vector<Vector>();
        if (openTours != null) {
            rowData = new Vector<Vector>();
            for (int i = 0; i < openTours.size(); i++) {
                Vector<String> row = new Vector<String>();
                row.addElement(openTours.get(i).getTour().getId());
                row.addElement(openTours.get(i).getTour().getName());
                DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
                StringBuilder dString = new StringBuilder(df.format(openTours.get(i).getTour().getStartDate()));
                row.addElement(dString.toString());
                row.addElement(openTours.get(i).getState());
                row.addElement(0 + "");
                rowData.add(row);

            }
        }
        table = new JTable(rowData, columNames);

        JScrollPane jScrollPane = new JScrollPane(table);
        jP.add(jScrollPane);
        return table;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        menuBar1 = new java.awt.MenuBar();
        menu1 = new java.awt.Menu();
        menu2 = new java.awt.Menu();
        tour_del_view = new javax.swing.JFrame("Delete tour");
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jComboBoxDelIds = new javax.swing.JComboBox();
        btDelAction = new javax.swing.JButton();
        tour_new_frame = new javax.swing.JFrame("Add a new tour");
        jPanelTourInfo = new javax.swing.JPanel();
        tf_new_startdate = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        tf_new_id = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tf_new_schedule = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        tf_new_btLoadImage = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        tf_new_name = new javax.swing.JTextField();
        tf_new_imgLink = new javax.swing.JTextField();
        new_combo_style = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        tf_new_maxnum1 = new javax.swing.JTextField();
        lb_new_state = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        tf_new_type = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        tf_new_discount = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tf_new_price = new javax.swing.JTextField();
        tf_new_stateDate = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        tf_new_duration = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        bt_new_save = new javax.swing.JButton();
        bt_new_clear = new javax.swing.JButton();
        tour_edit_frame = new javax.swing.JFrame();
        jPanel5 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        combo_tour_edit = new javax.swing.JComboBox();
        btEdit = new javax.swing.JButton();
        tour_open_form = new javax.swing.JFrame();
        jLabel16 = new javax.swing.JLabel();
        jPanelTourOpenTable = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        jComboBoxTourOpenId = new javax.swing.JComboBox();
        btOpenTour = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        btCloseTour = new javax.swing.JButton();
        jComboBoxCloseTour = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        tourEditInfoFrame = new javax.swing.JFrame();
        jPanelForTourView = new javax.swing.JPanel();
        btSaveChanges = new javax.swing.JButton();
        bt_add = new javax.swing.JButton();
        bt_edit = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tb_tour_info = new javax.swing.JTable();
        btOpenTourFrame = new javax.swing.JButton();
        btOpenDelForm = new javax.swing.JButton();

        menu1.setLabel("File");
        menuBar1.add(menu1);

        menu2.setLabel("Edit");
        menuBar1.add(menu2);

        tour_del_view.setBackground(new java.awt.Color(24, 19, 133));
        tour_del_view.setMinimumSize(new java.awt.Dimension(500, 300));

        jPanel2.setBackground(new java.awt.Color(255, 204, 204));
        jPanel2.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(255, 0, 0)));

        jLabel1.setText("Chọn mã tour cần xóa: ");
        jLabel1.setMaximumSize(new java.awt.Dimension(106, 18));
        jLabel1.setMinimumSize(new java.awt.Dimension(106, 18));

        jComboBoxDelIds.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btDelAction.setText("Xóa");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(199, Short.MAX_VALUE)
                .addComponent(jComboBoxDelIds, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(107, 107, 107))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(161, 161, 161)
                .addComponent(btDelAction)
                .addContainerGap(234, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(29, 29, 29)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(276, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(74, 74, 74)
                .addComponent(jComboBoxDelIds, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 122, Short.MAX_VALUE)
                .addComponent(btDelAction)
                .addGap(44, 44, 44))
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGap(76, 76, 76)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(193, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout tour_del_viewLayout = new javax.swing.GroupLayout(tour_del_view.getContentPane());
        tour_del_view.getContentPane().setLayout(tour_del_viewLayout);
        tour_del_viewLayout.setHorizontalGroup(
            tour_del_viewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tour_del_viewLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        tour_del_viewLayout.setVerticalGroup(
            tour_del_viewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tour_del_viewLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        tour_new_frame.setBackground(new java.awt.Color(153, 0, 0));

        tf_new_startdate.setBackground(new java.awt.Color(204, 255, 204));

        jLabel2.setText("Mã tour:*");

        tf_new_id.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_new_idActionPerformed(evt);
            }
        });

        jLabel3.setText("Lịch trình:");

        tf_new_schedule.setColumns(20);
        tf_new_schedule.setRows(5);
        jScrollPane1.setViewportView(tf_new_schedule);

        jLabel4.setText("Hình ảnh: ");

        tf_new_btLoadImage.setText("Load image");
        tf_new_btLoadImage.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_new_btLoadImageActionPerformed(evt);
            }
        });

        jLabel14.setText("Tên: ");

        javax.swing.GroupLayout tf_new_startdateLayout = new javax.swing.GroupLayout(tf_new_startdate);
        tf_new_startdate.setLayout(tf_new_startdateLayout);
        tf_new_startdateLayout.setHorizontalGroup(
            tf_new_startdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tf_new_startdateLayout.createSequentialGroup()
                .addGroup(tf_new_startdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tf_new_startdateLayout.createSequentialGroup()
                        .addGroup(tf_new_startdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(tf_new_startdateLayout.createSequentialGroup()
                                .addGap(19, 19, 19)
                                .addComponent(jLabel4))
                            .addGroup(tf_new_startdateLayout.createSequentialGroup()
                                .addGap(40, 40, 40)
                                .addGroup(tf_new_startdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel14))))
                        .addGap(49, 49, 49)
                        .addGroup(tf_new_startdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tf_new_startdateLayout.createSequentialGroup()
                                .addComponent(tf_new_imgLink, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(tf_new_btLoadImage))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tf_new_startdateLayout.createSequentialGroup()
                        .addGap(136, 136, 136)
                        .addComponent(tf_new_name, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE))
                    .addGroup(tf_new_startdateLayout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(jLabel2)
                        .addGap(57, 57, 57)
                        .addComponent(tf_new_id, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)))
                .addContainerGap())
        );
        tf_new_startdateLayout.setVerticalGroup(
            tf_new_startdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tf_new_startdateLayout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addGroup(tf_new_startdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_new_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(74, 74, 74)
                .addGroup(tf_new_startdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_new_name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 82, Short.MAX_VALUE)
                .addGroup(tf_new_startdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(tf_new_startdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tf_new_btLoadImage, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(tf_new_startdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tf_new_imgLink, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)))
                .addContainerGap())
        );

        new_combo_style.setBackground(new java.awt.Color(204, 255, 204));

        jLabel8.setText("Lượng khách tối đa");

        jLabel12.setText("Loại hình");

        tf_new_type.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel9.setText("Giảm giá: ");

        jLabel5.setText("Giá tiền: ");

        jLabel6.setText("Ngày đi:");

        jLabel7.setText("Thời lượng: ");

        javax.swing.GroupLayout new_combo_styleLayout = new javax.swing.GroupLayout(new_combo_style);
        new_combo_style.setLayout(new_combo_styleLayout);
        new_combo_styleLayout.setHorizontalGroup(
            new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(new_combo_styleLayout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addGroup(new_combo_styleLayout.createSequentialGroup()
                        .addGap(335, 335, 335)
                        .addComponent(lb_new_state, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE))))
            .addGroup(new_combo_styleLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel12)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(jLabel9))
                .addGap(45, 45, 45)
                .addGroup(new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(new_combo_styleLayout.createSequentialGroup()
                        .addComponent(tf_new_maxnum1, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(143, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, new_combo_styleLayout.createSequentialGroup()
                        .addGroup(new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tf_new_type, javax.swing.GroupLayout.Alignment.LEADING, 0, 180, Short.MAX_VALUE)
                            .addComponent(tf_new_price, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                            .addComponent(tf_new_discount, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                            .addComponent(tf_new_stateDate, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                            .addComponent(tf_new_duration, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
                        .addGap(140, 140, 140))))
        );
        new_combo_styleLayout.setVerticalGroup(
            new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(new_combo_styleLayout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addGroup(new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(tf_new_maxnum1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(tf_new_type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37)
                .addGroup(new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tf_new_price, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34)
                .addGroup(new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tf_new_discount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(46, 46, 46)
                .addGroup(new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(tf_new_stateDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(33, 33, 33)
                .addGroup(new_combo_styleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(tf_new_duration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(287, 287, 287)
                .addComponent(lb_new_state, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanelTourInfoLayout = new javax.swing.GroupLayout(jPanelTourInfo);
        jPanelTourInfo.setLayout(jPanelTourInfoLayout);
        jPanelTourInfoLayout.setHorizontalGroup(
            jPanelTourInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTourInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tf_new_startdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(new_combo_style, javax.swing.GroupLayout.PREFERRED_SIZE, 394, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelTourInfoLayout.setVerticalGroup(
            jPanelTourInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTourInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTourInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(new_combo_style, javax.swing.GroupLayout.Alignment.LEADING, 0, 622, Short.MAX_VALUE)
                    .addComponent(tf_new_startdate, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bt_new_save.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tourmanagementsystem/imgresource/save.png"))); // NOI18N
        bt_new_save.setText("Save");
        bt_new_save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_new_saveActionPerformed(evt);
            }
        });

        bt_new_clear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tourmanagementsystem/imgresource/clear.png"))); // NOI18N
        bt_new_clear.setText("Clear");
        bt_new_clear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_new_clearActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(554, Short.MAX_VALUE)
                .addComponent(bt_new_save)
                .addGap(39, 39, 39)
                .addComponent(bt_new_clear)
                .addGap(42, 42, 42))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_new_save)
                    .addComponent(bt_new_clear))
                .addGap(57, 57, 57))
        );

        javax.swing.GroupLayout tour_new_frameLayout = new javax.swing.GroupLayout(tour_new_frame.getContentPane());
        tour_new_frame.getContentPane().setLayout(tour_new_frameLayout);
        tour_new_frameLayout.setHorizontalGroup(
            tour_new_frameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tour_new_frameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tour_new_frameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelTourInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        tour_new_frameLayout.setVerticalGroup(
            tour_new_frameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tour_new_frameLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanelTourInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(121, 121, 121))
        );

        tour_edit_frame.getContentPane().setLayout(new java.awt.FlowLayout());

        jPanel5.setBackground(new java.awt.Color(153, 255, 153));

        jLabel11.setText("Chọn mã tour muốn sửa: ");

        combo_tour_edit.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btEdit.setText("Sửa");
        btEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(177, 177, 177)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(combo_tour_edit, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addContainerGap(148, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(373, Short.MAX_VALUE)
                .addComponent(btEdit)
                .addGap(38, 38, 38))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addComponent(jLabel11)
                .addGap(18, 18, 18)
                .addComponent(combo_tour_edit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 102, Short.MAX_VALUE)
                .addComponent(btEdit)
                .addGap(24, 24, 24))
        );

        tour_edit_frame.getContentPane().add(jPanel5);

        jLabel16.setText("Các tour đang mở: ");

        jLabel15.setText("Chọn mã tour để mở:");

        jComboBoxTourOpenId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btOpenTour.setText("Mở ");
        btOpenTour.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btOpenTourActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jComboBoxTourOpenId, 0, 122, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addContainerGap(41, Short.MAX_VALUE))))
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(52, 52, 52)
                .addComponent(btOpenTour, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(51, 51, 51))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel15)
                .addGap(11, 11, 11)
                .addComponent(jComboBoxTourOpenId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(btOpenTour)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        btCloseTour.setText("Đóng ");

        jComboBoxCloseTour.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel17.setText("Chọn mã tour để đóng");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxCloseTour, 0, 132, Short.MAX_VALUE)
                            .addComponent(jLabel17))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                        .addComponent(btCloseTour)
                        .addGap(63, 63, 63))))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addComponent(jComboBoxCloseTour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btCloseTour)
                .addGap(30, 30, 30))
        );

        javax.swing.GroupLayout tour_open_formLayout = new javax.swing.GroupLayout(tour_open_form.getContentPane());
        tour_open_form.getContentPane().setLayout(tour_open_formLayout);
        tour_open_formLayout.setHorizontalGroup(
            tour_open_formLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tour_open_formLayout.createSequentialGroup()
                .addGroup(tour_open_formLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tour_open_formLayout.createSequentialGroup()
                        .addGap(142, 142, 142)
                        .addComponent(jLabel16))
                    .addGroup(tour_open_formLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(tour_open_formLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(93, 93, 93)
                        .addComponent(jPanelTourOpenTable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(293, Short.MAX_VALUE))
        );
        tour_open_formLayout.setVerticalGroup(
            tour_open_formLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tour_open_formLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel16)
                .addGap(18, 18, 18)
                .addGroup(tour_open_formLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelTourOpenTable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29))
        );

        javax.swing.GroupLayout jPanelForTourViewLayout = new javax.swing.GroupLayout(jPanelForTourView);
        jPanelForTourView.setLayout(jPanelForTourViewLayout);
        jPanelForTourViewLayout.setHorizontalGroup(
            jPanelForTourViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 396, Short.MAX_VALUE)
        );
        jPanelForTourViewLayout.setVerticalGroup(
            jPanelForTourViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 263, Short.MAX_VALUE)
        );

        btSaveChanges.setText("Save");
        btSaveChanges.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSaveChangesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout tourEditInfoFrameLayout = new javax.swing.GroupLayout(tourEditInfoFrame.getContentPane());
        tourEditInfoFrame.getContentPane().setLayout(tourEditInfoFrameLayout);
        tourEditInfoFrameLayout.setHorizontalGroup(
            tourEditInfoFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tourEditInfoFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tourEditInfoFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(tourEditInfoFrameLayout.createSequentialGroup()
                        .addComponent(jPanelForTourView, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tourEditInfoFrameLayout.createSequentialGroup()
                        .addComponent(btSaveChanges)
                        .addGap(36, 36, 36))))
        );
        tourEditInfoFrameLayout.setVerticalGroup(
            tourEditInfoFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tourEditInfoFrameLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelForTourView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addComponent(btSaveChanges)
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(0, 102, 102));

        bt_add.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tourmanagementsystem/imgresource/add.png"))); // NOI18N
        bt_add.setText("Thêm tour");
        bt_add.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        bt_add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_addActionPerformed(evt);
            }
        });

        bt_edit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tourmanagementsystem/imgresource/edit.png"))); // NOI18N
        bt_edit.setText("Sửa tour");
        bt_edit.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        bt_edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_editActionPerformed(evt);
            }
        });

        tb_tour_info.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "TourID", "Start Date", "State", "Price"
            }
        ));
        jScrollPane2.setViewportView(tb_tour_info);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 508, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        btOpenTourFrame.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tourmanagementsystem/imgresource/view.png"))); // NOI18N
        btOpenTourFrame.setText("Mở tour");

        btOpenDelForm.setIcon(new javax.swing.ImageIcon(getClass().getResource("/tourmanagementsystem/imgresource/delete.png"))); // NOI18N
        btOpenDelForm.setText("Xóa tour");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(btOpenTourFrame, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(bt_edit, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(bt_add, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(btOpenDelForm, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(31, 31, 31)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(39, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(bt_add)
                        .addGap(52, 52, 52)
                        .addComponent(btOpenDelForm)
                        .addGap(48, 48, 48)
                        .addComponent(bt_edit)
                        .addGap(45, 45, 45)
                        .addComponent(btOpenTourFrame))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void tf_new_idActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_new_idActionPerformed
}//GEN-LAST:event_tf_new_idActionPerformed

private void bt_addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_addActionPerformed
    tour_new_frame.setLocation(200, 100);
    tour_new_frame.setSize(900, 800);
    tour_new_frame.setVisible(true);

}//GEN-LAST:event_bt_addActionPerformed

private void bt_editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_editActionPerformed
    tour_edit_frame.setSize(500, 300);
    tour_edit_frame.setLocation(200, 100);
    tour_edit_frame.setVisible(true);
    ArrayList<Tour> tours = new ArrayList<Tour>();
    try {
        tours = controller.getAllTours("tour", "");
        System.out.println("tours " + tours.size());
    } catch (Exception ex) {
        Logger.getLogger(TourManageFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
    addDataToComboBox(tours, CB_SUA);
}//GEN-LAST:event_bt_editActionPerformed

private void tf_new_btLoadImageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_new_btLoadImageActionPerformed
// TODO add your handling code here:

    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.showOpenDialog(null);
    File selectedPfile = chooser.getSelectedFile();
    tf_new_imgLink.setText(selectedPfile.getAbsolutePath());

}//GEN-LAST:event_tf_new_btLoadImageActionPerformed

private void bt_new_clearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_new_clearActionPerformed
// TODO add your handling code here:
    tf_new_discount.setText("");
    tf_new_duration.setText("");
    tf_new_id.setText("");
    tf_new_maxnum1.setText("");
    tf_new_price.setText("");
    tf_new_name.setText("");
    tf_new_schedule.setText("");
}//GEN-LAST:event_bt_new_clearActionPerformed

private void bt_new_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_new_saveActionPerformed
// TODO add your handling code here:
    Tour tour = getTourInput();
    System.out.println("tour input " + tour);
    try {
        controller.insertTour(tour, "add");
    } catch (Exception ex) {
        Logger.getLogger(TourManageFrame.class.getName()).log(Level.SEVERE, null, ex);
        showWarning("khong the them tour, err " + ex.getMessage());
    }

}//GEN-LAST:event_bt_new_saveActionPerformed

private void btSaveChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSaveChangesActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btSaveChangesActionPerformed

private void btEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditActionPerformed
    String id = combo_tour_edit.getSelectedItem().toString();
    Tour t = null;
    try {
        t = controller.findTourById(id);
    } catch (Exception ex) {
        Logger.getLogger(TourManageFrame.class.getName()).log(Level.SEVERE, null, ex);
        return;
    }
    if (t == null) {
        return;
    }
//   
    JFrame editFrame = new JFrame("Nhap thong tin muon sua");
    editFrame.setLayout(new FlowLayout());
    editFrame.add(jPanelTourInfo);
    JButton bt = new JButton("Lưu thay đổi");
    editFrame.add(bt);
    addDataToFrame(editFrame, t);
    editFrame.setSize(800, 800);
    editFrame.setVisible(true);
    bt.addActionListener(controller);

}//GEN-LAST:event_btEditActionPerformed

private void btOpenTourActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOpenTourActionPerformed
String idOpen = jComboBoxTourOpenId.getSelectedItem().toString();
Tour_Customer c = new Tour_Customer();
        try {
            c.setTour(controller.findTourById(idOpen));
             controller.insertTour_Cus(c);
             showWarning("Mo tour " + idOpen + " thanh cong");
             
        } catch (Exception ex) {
            Logger.getLogger(TourManageFrame.class.getName()).log(Level.SEVERE, null, ex);
            showWarning("Error : " + ex.getMessage());
        }
        ArrayList<Tour_Customer> toursC = new ArrayList<Tour_Customer>();
        toursC.add(c);
addTable(toursC);
        
}//GEN-LAST:event_btOpenTourActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCloseTour;
    private javax.swing.JButton btDelAction;
    private javax.swing.JButton btEdit;
    private javax.swing.JButton btOpenDelForm;
    private javax.swing.JButton btOpenTour;
    private javax.swing.JButton btOpenTourFrame;
    private javax.swing.JButton btSaveChanges;
    private javax.swing.JButton bt_add;
    private javax.swing.JButton bt_edit;
    private javax.swing.JButton bt_new_clear;
    private javax.swing.JButton bt_new_save;
    private javax.swing.JComboBox combo_tour_edit;
    private javax.swing.JComboBox jComboBoxCloseTour;
    private javax.swing.JComboBox jComboBoxDelIds;
    private javax.swing.JComboBox jComboBoxTourOpenId;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanelForTourView;
    private javax.swing.JPanel jPanelTourInfo;
    private javax.swing.JPanel jPanelTourOpenTable;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lb_new_state;
    private java.awt.Menu menu1;
    private java.awt.Menu menu2;
    private java.awt.MenuBar menuBar1;
    private javax.swing.JPanel new_combo_style;
    private javax.swing.JTable tb_tour_info;
    private javax.swing.JButton tf_new_btLoadImage;
    private javax.swing.JTextField tf_new_discount;
    private javax.swing.JTextField tf_new_duration;
    private javax.swing.JTextField tf_new_id;
    private javax.swing.JTextField tf_new_imgLink;
    private javax.swing.JTextField tf_new_maxnum1;
    private javax.swing.JTextField tf_new_name;
    private javax.swing.JTextField tf_new_price;
    private javax.swing.JTextArea tf_new_schedule;
    private javax.swing.JPanel tf_new_startdate;
    private javax.swing.JTextField tf_new_stateDate;
    private javax.swing.JComboBox tf_new_type;
    private javax.swing.JFrame tourEditInfoFrame;
    private javax.swing.JFrame tour_del_view;
    private javax.swing.JFrame tour_edit_frame;
    private javax.swing.JFrame tour_new_frame;
    private javax.swing.JFrame tour_open_form;
    // End of variables declaration//GEN-END:variables

    public void addDataToComboBox(ArrayList<Tour> t, String string) {
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        if (t == null) {
            showWarning("khong co du lieu!");
            return;
        }
        for (Tour ts : t) {
            System.out.println(ts);
            model.addElement(ts.getId());
        }
        if (string.equals(CB_XOA)) {
            jComboBoxDelIds.setModel(model);
        } else if (string.equals(CB_SUA)) {
            System.out.println("");
            combo_tour_edit.setModel(model);
        }
        else if(string.equals(CB_MO)){
            jComboBoxTourOpenId.setModel(model);
        }

    }

    private void addDataToFrame(JFrame tour_new_frame, Tour tour) {
        if (tour == null) {
            return;
        }
        tf_new_id.setText(tour.getId());
        tf_new_imgLink.setText(tour.getImgLink());
        tf_new_discount.setText(tour.getDiscount() + "");
        tf_new_name.setText(tour.getName());
        tf_new_price.setText(tour.getPrice() + "");
        tf_new_maxnum1.setText(tour.getMaxP() + "");
        tf_new_schedule.setText(tour.getSchedule());
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        StringBuilder dString = new StringBuilder(df.format(tour.getStartDate()));
        tf_new_stateDate.setText(dString.toString());
        tf_new_duration.setText(tour.getDuration() + "");
        tf_new_type.setSelectedIndex(tour.getType());

    }

    private void showFullTourInfoToTable(ArrayList<Tour> tours, JTable jTableEdit) {
    }
}
